/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package comandaXM.vista.auxiliars;

import comandaXM.utils.eventXM.IListenerXM;
import comandaXM.utils.TDSLanguageUtils;
import comandaXM.utils.ValidarText;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;



/**
 *
 * @author xmarti
 */
public abstract  class JPAuxiliarData2 extends javax.swing.JPanel implements IListenerXM {

    /**
     * Creates new form JPStateData
     */
    private List listeners = new ArrayList();

    public JPAuxiliarData2(boolean numeric) {
        initComponents();        
        this.jTextCode.setDocument(new ValidarText(4,numeric,true));       
        this.jTextName.setDocument(new ValidarText(50,false,true));
        

    }
   
    public String getCodeAuxiliar(){
        return this.jTextCode.getText();        
    }
    public void setCodeAuxiliar(String code){
        this.jTextCode.setText(code);      
        this.jTextCode.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        this.jLabelCodeERR.setVisible(false);
    }  
    
    public String getNameAuxiliar (){
        return this.jTextName.getText();
    }
    public void setNameAuxiliar(String name){
        this.jTextName.setText(name);
        this.jTextName.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 10, 1, 1));
        this.jLabelNameERR.setVisible(false);
    }
    public void setErrorCode(String err ){
       this.jLabelCodeERR.setText(err);
       this.jLabelCodeERR.setVisible(true); 
       this.jTextCode.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, java.awt.Color.red));
       
    }
    public void setErrorName(String err ){
       this.jLabelNameERR.setText(err);
       this.jLabelNameERR.setVisible(true); 
       this.jTextName.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 10, 1, 1, java.awt.Color.red));
       
    }     
     public void setRequestFocus(){
        this.jTextCode.requestFocus();
        this.jTextCode.select(0, this.jTextCode.getText().length());
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelNameERR = new javax.swing.JLabel();
        jTextCode = new javax.swing.JTextField();
        jLabelDescription = new javax.swing.JLabel();
        jTextName = new javax.swing.JTextField();
        jLabelCaptionName2 = new javax.swing.JLabel();
        jLabelCodeERR = new javax.swing.JLabel();

        setLayout(null);

        jLabelNameERR.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelNameERR.setForeground(java.awt.Color.red);
        jLabelNameERR.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        add(jLabelNameERR);
        jLabelNameERR.setBounds(360, 50, 270, 33);

        jTextCode.setBackground(new java.awt.Color(255, 255, 204));
        jTextCode.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jTextCode.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextCode.setAlignmentX(0.0F);
        jTextCode.setAlignmentY(0.0F);
        jTextCode.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jTextCode.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextCodeKeyPressed(evt);
            }
        });
        add(jTextCode);
        jTextCode.setBounds(100, 10, 50, 33);

        jLabelDescription.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelDescription.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelDescription.setText(TDSLanguageUtils.getMessage("jPanelAuxiliar.JLabel.name.caption"));
        add(jLabelDescription);
        jLabelDescription.setBounds(10, 50, 80, 33);

        jTextName.setBackground(new java.awt.Color(255, 255, 204));
        jTextName.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jTextName.setAlignmentX(0.0F);
        jTextName.setAlignmentY(0.0F);
        jTextName.setBorder(javax.swing.BorderFactory.createMatteBorder(1, 10, 1, 1, java.awt.Color.red));
        jTextName.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextNameKeyPressed(evt);
            }
        });
        add(jTextName);
        jTextName.setBounds(100, 50, 253, 33);

        jLabelCaptionName2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelCaptionName2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelCaptionName2.setText(TDSLanguageUtils.getMessage("jPanelAuxiliar.JLabel.code.caption"));
        add(jLabelCaptionName2);
        jLabelCaptionName2.setBounds(10, 10, 80, 33);

        jLabelCodeERR.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabelCodeERR.setForeground(java.awt.Color.red);
        jLabelCodeERR.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        add(jLabelCodeERR);
        jLabelCodeERR.setBounds(170, 10, 420, 33);
    }// </editor-fold>//GEN-END:initComponents

    private void jTextCodeKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextCodeKeyPressed
       if (evt.getKeyCode()==38){
           notifyKeyPressed(-1);  
       }else if (evt.getKeyCode()==40){
           notifyKeyPressed(1);  
       }
           
    }//GEN-LAST:event_jTextCodeKeyPressed

    private void jTextNameKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextNameKeyPressed
       if (evt.getKeyCode()==38){
           notifyKeyPressed(-1);  
       }else if (evt.getKeyCode()==40){
           notifyKeyPressed(1);  
       }
    }//GEN-LAST:event_jTextNameKeyPressed
    public synchronized void addKeyCodeListener(IListenerXM listener){
        listeners.add(listener); 
    }
    public synchronized void removeKeyCodeListener (IListenerXM listener){
        listeners.remove(listener); 
    }
    protected void notifyKeyPressed (int increment){
        List tempList; 
        synchronized (this){
            tempList= (List)((ArrayList)listeners).clone(); 
        }
      for (Iterator it= tempList.iterator();it.hasNext();){
         ((IListenerXM) it.next()).movePosition(increment); 
      }
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabelCaptionName2;
    private javax.swing.JLabel jLabelCodeERR;
    private javax.swing.JLabel jLabelDescription;
    private javax.swing.JLabel jLabelNameERR;
    private javax.swing.JTextField jTextCode;
    private javax.swing.JTextField jTextName;
    // End of variables declaration//GEN-END:variables

   
    
  
}
